﻿Imports BUS
Imports DTO

Public Class frmTiepNhanHocSinh

    Dim lhBus As New LopHocBus()
    Dim danhSachLop As List(Of LopHocDto)
    Private siSo As Integer

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub

    Private Sub LoadLopHoc()
        danhSachLop = lhBus.LayDSLop()
        cbbLopHoc.DataSource = danhSachLop
        cbbLopHoc.ValueMember = "MaLop"
        cbbLopHoc.DisplayMember = "TenLop"
    End Sub

    Private Sub Clear()
        txtHoTen.Text = ""
        cboGioiTinh.SelectedIndex = 0
        dtpNgaySinh.Value = Date.Now.ToString()
        txtDiaChi.Text = ""
        txtEmail.Text = ""
    End Sub

    Private Sub TiepNhanHocSinh()

        Dim hsDTO As New HocSinhDto()
        hsDTO.TenHS = txtHoTen.Text
        hsDTO.GioiTinh = cboGioiTinh.Text
        hsDTO.NgaySinh = dtpNgaySinh.Value
        hsDTO.DiaChi = txtDiaChi.Text
        hsDTO.Email = txtEmail.Text

        danhSachLop = lhBus.LayDSLop()
        For i As Integer = 0 To danhSachLop.Count - 1
            If danhSachLop(i).MaLop = cbbLopHoc.SelectedValue Then
                siSo = danhSachLop(i).SiSo
            End If
        Next

        Dim lh As LopHocDto = cbbLopHoc.SelectedItem
        Dim maLop As Integer = lh.MaLop
        siSo = siSo + 1
        If (HocSinhBus.ThemHocSinh(hsDTO, maLop, siSo)) Then
            MessageBox.Show("Them thanh cong", "Thong bao")
            Clear()
        Else
            MessageBox.Show("Them that bai", "Thong bao")
        End If

    End Sub

    Private Sub frmTiepNhanHocSinh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cboGioiTinh.SelectedItem = cboGioiTinh.Items(0)
        LoadLopHoc()
    End Sub

    Private Sub btnTiepNhan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTiepNhan.Click
        TiepNhanHocSinh()
    End Sub

End Class